﻿<%@ WebHandler Language="C#" Class="ContainerStepWorkReportVue3PageHandler" %>

/*Description:新报工后端接口
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:zhunan 
'create Date:2024.1.15
*/
using System;
using System.IO;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Data;
using System.Text;
using BusinessRule.DTO;
using DatabaseAccess.DBUtility;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using System.Net;
using System.Configuration;
using StackExchange.Redis;
using BusinessRule.Common;
using System.Linq;

public class ContainerStepWorkReportVue3PageHandler : IHttpHandler
{
    public class PageObjectTree
    {
        //全局变量用于保存数据
        private List<PageObjectTree> treeNode = new List<PageObjectTree>();
        public string label { get; set; }
        public string id { get; set; }
        public string type { get; set; }

        public IList<PageObjectTree> children = new List<PageObjectTree>();
        //递归生成树
        public List<PageObjectTree> BindTree(DataTable dtSource, PageObjectTree parentNode, string parentID)
        {
            DataRow[] rows = dtSource.Select(string.Format("parentid = '{0}'", parentID));
            foreach (DataRow row in rows)
            {
                PageObjectTree tree = new PageObjectTree();
                tree.label = row["label"].ToString();
                tree.id = row["id"].ToString();
                tree.type = row["type"].ToString();

                //递归
                BindTree(dtSource, tree, row["id"].ToString());

                if (parentNode == null)
                {
                    treeNode.Add(tree);
                }
                else
                {
                    parentNode.children.Add(tree);
                }
            }
            return treeNode;
        }
    }

    YPContainerBusiness ypContainerBusiness = new YPContainerBusiness();
    uLMSCommonIBusiness m_Common = uMESBusinessFactory.instance.GetuLMSCommonObject();
    uLMSBathResMonitorBusiness bath = new uLMSBathResMonitorBusiness();
    uLMSWorkReportIBusiness m_ReportBusiness = uMESBusinessFactory.instance.GetuLMSWorkReportObject();
    uLMSDispatchIBusiness m_DispatchObj = uMESBusinessFactory.instance.GetuLMSDispatchObject();
    uLMSDocumetViewIBusiness m_DocViewObj = uMESBusinessFactory.instance.GetuLMSDocumetViewObject();
    uLMSContainerIBusiness m_ContainerObj = uMESBusinessFactory.instance.GetuLMSContainerObject();
    uLMSIssueIBusiness m_issueData = uMESBusinessFactory.instance.GetuLMSIssueObject();
    uLMSContainercurrentinfoIBusiness m_ConCurrentinfoObj = uMESBusinessFactory.instance.GetuLMSContainerCurrentInfoObject();

    RedisHelper redis = new RedisHelper();
    string redis_Lock = "MESAPP_ReportPage_Lock";
    RedisValue[] redis_dispatchIDs;
    bool isGivenTogetherflag = false;
    string togetherflag = "";

    public bool IsReusable { get { return false; } }
    public void ProcessRequest(HttpContext context)
    {
        string requestjson = "";
        using (System.IO.StreamReader reader = new StreamReader(context.Request.InputStream)) { requestjson = reader.ReadToEnd(); }
        JObject jObject = JsonConvert.DeserializeObject(requestjson) as JObject;
        if (jObject["type"] != null)
        {
            try
            {
                uMESProcessResult r = new uMESProcessResult();
                context.Response.ContentType = "text/json";
                string type = jObject["type"].ToString();
                switch (type)
                {
                    case "getUnReceivedData":
                        r = getUnReceivedData(jObject);//查询待领工任务
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getUnReportedData":
                        r = getUnReportedData(jObject);//查询待报工任务
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getContainerType7List":
                        r = getContainerType7List(jObject);//查询单件单卡子批次
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getContainerType3List":
                        r = getContainerType3List(jObject);//查询批量带子序号批次
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getDispatchAndReportInfo":
                        r = getDispatchAndReportInfo(jObject);//查询派工及已报工信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getResourceList":
                        r = getResourceList(jObject);//查询工序设备信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getFactoryUserattributes":
                        r = getFactoryUserattributes(jObject);//查询分厂属性
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getEmployeeByCardNum":
                        r = getEmployeeByCardNum(jObject);//报工扫卡工区长、班组长
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getFirstContainerData":
                        r = getFirstContainerData(jObject);//查询叶片首件批次号数据
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "saveWorkReport":
                        r = saveWorkReport(jObject);//保存报工信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "saveReceive":
                        r = saveReceive(jObject);//保存领工信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getScanContainerData":
                        r = getScanContainerData(jObject);//扫卡
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getDocumentViewTreeData":
                        r = getDocumentViewTreeData(jObject);//查询工艺查看Tree数据
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getDocumentList":
                        r = getDocumentList(jObject);//查询文档列表
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getDownloadUrl":
                        r = getDownloadUrl(jObject);//获取文档下载url
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getMESFeedBackData":
                        r = getMESFeedBackData(jObject);//获取问题快反相关数据
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "checkReceiveData":
                        r = checkReceiveData(jObject);//领工数据校验
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "checkReportData":
                        r = checkReportData(jObject);//报工数据校验
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getEmployeeWorkdate":
                        r = getEmployeeWorkdate(jObject);//查询人员排班信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getWorkerWorkTime":
                        r = getWorkerWorkTime(jObject);//查询工人本月工时
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getSurpassbillInfoList":
                        r = getSurpassbillInfoList(jObject);//查询超越单信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getSurpassbillDocList":
                        r = getSurpassbillDocList(jObject);//查询超越单附件信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getResourceStatusListData":
                        r = getResourceStatusListData(jObject);//查询设备状态录入信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "setResourceStatus":
                        r = setResourceStatus(jObject);//设备状态信息保存
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getCollectInfo":
                        r = getCollectInfo(jObject);//查询集件信息
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getUnCheckData":
                        r = getUnCheckData(jObject);//查询待检验数据
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getUnCheckDetailInfo":
                        r = getUnCheckDetailInfo(jObject);//查询待检验明细数据
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "revokeReceiveData":
                        r = revokeReceiveData(jObject);//撤销领工
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "revokeReportData":
                        r = revokeReportData(jObject);//撤销报工
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "checkReceiveStatus":
                        r = checkReceiveStatus(jObject);//撤销领工校验
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getUnReportWorkflowStepCount":
                        r = getUnReportWorkflowStepCount(jObject);//查询已派工未报工工序数
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getUnReportWorkflowStepDetail":
                        r = getUnReportWorkflowStepDetail(jObject);//查询已派工未报工工序明细
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getNCProgramData":
                        r = getNCProgramData(jObject);//查询件号NC程序列表
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    case "getNCProgramDetail":
                        r = getNCProgramDetail(jObject);//查询件号NC程序明细
                        context.Response.Write(JsonConvert.SerializeObject(r));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                uMESProcessResult r = new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "500", Message = e.Message };
                context.Response.ContentType = "text/json";
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
    }

    //查询待领工任务
    uMESProcessResult getUnReceivedData(JObject jObject)
    {
        string sql = @"
SELECT *
FROM (
SELECT NVL(c.workflowroute,c.productname) productname,c.productid,ws.workflowstepname,ws.workflowstepid,s.specno, ws.workflowid,ws.sequence,c.togetherflag,
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,
       c.mfgordername,c.planqty,c.factoryid,(c.productname||'/'||c.containerno) productbatch,s.iskey,   
       SUM(c.qty) AS wipqty ,'' containerid,'' containername,'' facontianerid,'' bomid,
       '' containerstepdispatchid,--单件单卡派工id为空
       '' resourceid,c.workflowstepname nowworkflowstepname,'' ishold,
       c.workflowstepid nowworkflowstepid,NULL firstchecknum,NULL stepchecknum,NULL prioritycode,c.productdescription,c.productrevision,NULL plannedstartdate,
       MAX(csd.plannedfinishdate) plannedfinishdate,NULL dispatchdate,NULL workreportnum,NULL alllossqty
FROM containercurrentinfo c 
LEFT JOIN containerstepdispatch csd ON csd.containerid = c.containerid AND csd.isuse = 0
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN workflow wf ON wf.workflowid = ws.workflowid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid, ws.specid)
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
WHERE c.dispatchnum = 1 AND c.splitnum = 0 AND NVL(csd.iscomplete,0) = 0 AND c.factoryid='{0}' 
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{1}') OR (csd.workerid IS NULL AND csdd.workerid='{1}'))  
      AND c.containerstatus=1 AND c.isinstore=0
      AND csd.workflowstepid = c.workflowstepid
      AND c.qty+NVL(c.alllossqty,0)>NVL(c.workreportnum,0)
      AND c.containertype ='7'
      AND csd.recvdate IS NULL";

        if (isGivenTogetherflag)
        {
            sql += " AND c.togetherflag = '{2}' ";
        }

        if (jObject["togetherflag"].ToString() != "")
        {
            sql += string.Format(" AND c.togetherflag = '{0}'", jObject["togetherflag"].ToString());
        }

        if (jObject["productname"] != null && jObject["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", jObject["productname"].ToString());
        }

        if (jObject["mfgordername"] != null && jObject["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", jObject["mfgordername"].ToString());
        }

        sql += @"
GROUP BY c.productid,c.productname,ws.workflowstepname,ws.workflowstepid,ws.workflowid,ws.sequence,s.specno,c.togetherflag,
         c.containertype,c.mfgordername,c.planqty,c.factoryid,c.productdescription,c.productrevision,
         c.workflowstepname,c.workflowstepid,c.workflowroute,c.containerno,s.iskey
UNION ALL 

SELECT NVL(c.workflowroute,c.productname) productname,c.productid,ws.workflowstepname,ws.workflowstepid,s.specno, ws.workflowid,ws.sequence,c.togetherflag,
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,
       c.mfgordername,c.planqty,c.factoryid,(c.productname||'/'||c.containerno) productbatch,s.iskey,
       c.qty AS wipqty ,c.containerid,c.containername,c.containerid AS facontianerid,c.bomid,csd.containerstepdispatchid,
       csd.resourceid,c.workflowstepname nowworkflowstepname,c.ishold,
       c.workflowstepid nowworkflowstepid,c.firstchecknum,c.stepchecknum,csd.prioritycode,c.productdescription,c.productrevision,
       csd.plannedstartdate,csd.plannedfinishdate,TRUNC(csd.createdate) dispatchdate,c.workreportnum,c.alllossqty
FROM containercurrentinfo c 
LEFT JOIN containerstepdispatch csd ON csd.containerid = c.containerid AND csd.isuse = 0
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN workflow wf ON wf.workflowid = ws.workflowid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid, ws.specid)
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid 
WHERE c.dispatchnum = 1 AND c.splitnum = 0 AND NVL(csd.iscomplete,0) = 0 AND c.factoryid='{0}' 
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{1}') OR (csd.workerid IS NULL AND csdd.workerid='{1}'))  
      AND c.containerstatus=1 AND c.isinstore=0
      AND csd.workflowstepid = c.workflowstepid
      AND c.qty+NVL(c.alllossqty,0)>NVL(c.workreportnum,0)
      AND c.containertype <> '7'
      AND csd.recvdate IS NULL";
        if (isGivenTogetherflag)
        {
            sql += " AND c.togetherflag = '{2}' ";
        }

        if (jObject["togetherflag"].ToString() != "")
        {
            sql += string.Format(" AND c.togetherflag = '{0}'", jObject["togetherflag"].ToString());
        }

        if (jObject["productname"] != null && jObject["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", jObject["productname"].ToString());
        }

        if (jObject["mfgordername"] != null && jObject["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", jObject["mfgordername"].ToString());
        }
        sql += @"
) c 
ORDER BY c.plannedfinishdate";
        string factoryid = jObject["factoryid"] != null ? jObject["factoryid"].ToString() : "";
        string workerid = jObject["workerid"] != null ? jObject["workerid"].ToString() : "";

        if (isGivenTogetherflag)
        {
            sql = string.Format(sql, factoryid, workerid, togetherflag);
        }
        else
        {
            sql = string.Format(sql, factoryid, workerid);
        }

        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }

        //过滤批次当前序存在测试件检验(type=3)
        int doindex = 0;
        while (doindex < dt.Rows.Count)
        {
            DataRow row;
            for (int i = doindex; i < dt.Rows.Count; i++)
            {
                doindex += 1;
                row = dt.Rows[i];
                if (row["ContainerType"].ToString() != "2")
                {
                    continue;
                }
                int count = m_ReportBusiness.GetContainerCurrentIsReportType_3(row["CONTAINERID"].ToString(), row["WORKFLOWSTEPID"].ToString());
                if (count > 0 && row["STEPCHECKNUM"].ToString() == "1")
                {
                    row.Delete();
                    dt.AcceptChanges();
                    doindex -= 1;
                    break;
                }
            }
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询待报工任务
    uMESProcessResult getUnReportedData(JObject jObject)
    {
        string sql = @"
SELECT *
FROM (
SELECT NVL(c.workflowroute,c.productname) productname,c.productid,ws.workflowstepname,ws.workflowstepid,s.specno, ws.workflowid,ws.sequence,c.togetherflag,
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,
       c.mfgordername,c.planqty,c.factoryid,(c.productname||'/'||c.containerno) productbatch,s.iskey,   
       SUM(c.qty) AS wipqty ,'' containerid,'' containername,'' facontianerid,''bomid,
       '' containerstepdispatchid,--单件单卡派工id为空
       '' resourceid,c.workflowstepname nowworkflowstepname,'' ishold,
       c.workflowstepid nowworkflowstepid,NULL firstchecknum,NULL stepchecknum,NULL prioritycode,c.productdescription,c.productrevision,NULL plannedstartdate,
       NULL plannedfinishdate,NULL dispatchdate,NULL workreportnum,NULL alllossqty,NULL receiveEmp,NULL receiveDate
FROM containercurrentinfo c 
LEFT JOIN containerstepdispatch csd ON csd.containerid = c.containerid AND csd.isuse = 0
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN workflow wf ON wf.workflowid = ws.workflowid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid, ws.specid)
WHERE c.dispatchnum = 1 AND c.splitnum = 0 AND NVL(csd.iscomplete,0) = 0 AND c.factoryid='{0}' 
      --AND csd.recvemployeeid = '{1}' --谁领的工，只能谁去报工。
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{1}') OR (csd.workerid IS NULL AND csdd.workerid='{1}'))
      AND c.containerstatus=1 AND c.isinstore=0
      AND csd.workflowstepid = c.workflowstepid
      AND c.qty+NVL(c.alllossqty,0)>NVL(c.workreportnum,0)
      AND c.containertype ='7'
      AND csd.recvdate IS NOT NULL";
        if (isGivenTogetherflag)
        {
            sql += " AND c.togetherflag = '{2}' ";
        }

        if (jObject["togetherflag"].ToString() != "")
        {
            sql += string.Format(" AND c.togetherflag = '{0}'", jObject["togetherflag"].ToString());
        }

        if (jObject["productname"] != null && jObject["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", jObject["productname"].ToString());
        }

        if (jObject["mfgordername"] != null && jObject["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", jObject["mfgordername"].ToString());
        }

        sql += @"
GROUP BY c.productid,c.productname,ws.workflowstepname,ws.workflowstepid,ws.workflowid,ws.sequence,s.specno,c.togetherflag,
         c.containertype,c.mfgordername,c.planqty,c.factoryid,c.productdescription,c.productrevision,
         c.workflowstepname,c.workflowstepid,c.workflowroute,c.containerno,s.iskey
UNION ALL 

SELECT NVL(c.workflowroute,c.productname) productname,c.productid,ws.workflowstepname,ws.workflowstepid,s.specno, ws.workflowid,ws.sequence,c.togetherflag,
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,
       c.mfgordername,c.planqty,c.factoryid,(c.productname||'/'||c.containerno) productbatch,s.iskey,
       c.qty AS wipqty ,c.containerid,c.containername,c.containerid AS facontianerid,c.bomid,csd.containerstepdispatchid,
       csd.resourceid,c.workflowstepname nowworkflowstepname,c.ishold,
       c.workflowstepid nowworkflowstepid,c.firstchecknum,c.stepchecknum,csd.prioritycode,c.productdescription,c.productrevision,
       csd.plannedstartdate,csd.plannedfinishdate,TRUNC(csd.createdate) dispatchdate,c.workreportnum,c.alllossqty,e.fullname receiveEmp,csd.recvdate receiveDate
FROM containercurrentinfo c 
LEFT JOIN containerstepdispatch csd ON csd.containerid = c.containerid AND csd.isuse = 0
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN workflow wf ON wf.workflowid = ws.workflowid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid, ws.specid)
LEFT JOIN employee e ON e.employeeid = csd.recvemployeeid
WHERE c.dispatchnum = 1 AND c.splitnum = 0 AND NVL(csd.iscomplete,0) = 0 AND c.factoryid='{0}' 
      --AND csd.recvemployeeid = '{1}' --谁领的工，只能谁去报工。
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{1}') OR (csd.workerid IS NULL AND csdd.workerid='{1}'))
      AND c.containerstatus=1 AND c.isinstore=0
      AND csd.workflowstepid = c.workflowstepid
      AND c.qty+NVL(c.alllossqty,0)>NVL(c.workreportnum,0)
      AND c.containertype <> '7'
      AND csd.recvdate IS NOT NULL";

        if (isGivenTogetherflag)
        {
            sql += " AND c.togetherflag = '{2}' ";
        }

        if (jObject["togetherflag"].ToString() != "")
        {
            sql += string.Format(" AND c.togetherflag = '{0}'", jObject["togetherflag"].ToString());
        }

        if (jObject["productname"] != null && jObject["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", jObject["productname"].ToString());
        }

        if (jObject["mfgordername"] != null && jObject["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", jObject["mfgordername"].ToString());
        }

        sql += @"
) c 
ORDER BY c.productid,c.containerid,c.sequence";
        string factoryid = jObject["factoryid"] != null ? jObject["factoryid"].ToString() : "";
        string workerid = jObject["workerid"] != null ? jObject["workerid"].ToString() : "";

        if (isGivenTogetherflag)
        {
            sql = string.Format(sql, factoryid, workerid, togetherflag);
        }
        else
        {
            sql = string.Format(sql, factoryid, workerid);
        }

        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }

        //过滤批次当前序存在测试件检验(type=3)
        int doindex = 0;
        while (doindex < dt.Rows.Count)
        {
            DataRow row;
            for (int i = doindex; i < dt.Rows.Count; i++)
            {
                doindex += 1;
                row = dt.Rows[i];
                if (row["ContainerType"].ToString() != "2")
                {
                    continue;
                }
                int count = m_ReportBusiness.GetContainerCurrentIsReportType_3(row["CONTAINERID"].ToString(), row["WORKFLOWSTEPID"].ToString());
                if (count > 0 && row["STEPCHECKNUM"].ToString() == "1")
                {
                    row.Delete();
                    dt.AcceptChanges();
                    doindex -= 1;
                    break;
                }
            }
        }

        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询单件单卡批次信息
    uMESProcessResult getContainerType7List(JObject jObject)
    {
        string sql = @"
SELECT  c.containerid,c.containername,c.productname,c.productid,ws.workflowstepname,
        ws.workflowstepid,
        c.workflowstepid nowworkflowstepid,
        s.specno,c.qty,ws.workflowid,ws.sequence, 
        c.togetherflag,REPLACE(c.togetherflag,c.productname||'/','') togetherflagname,c.workflowstepname nowworkflowstepname,c.ishold,
        c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,c.mfgordername,c.planqty,
        c.factoryid,csd.containerstepdispatchid,csd.resourceid,csd.prioritycode,csd.plannedstartdate,csd.plannedfinishdate,TRUNC(csd.createdate) dispatchdate,
        e.fullname receiveemp,csd.recvdate receivedate,c.bomid
FROM containercurrentinfo c 
LEFT JOIN containerstepdispatch csd ON csd.containerid = c.containerid AND csd.isuse = 0
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN workflow wf ON wf.workflowid = ws.workflowid
LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid
LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid, ws.specid)
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
LEFT JOIN employee e ON e.employeeid = csd.recvemployeeid
WHERE c.dispatchnum = 1 AND c.splitnum = 0 AND NVL(csd.iscomplete,0) = 0 
      AND c.containerstatus=1 AND c.isinstore=0
      AND csd.workflowstepid = c.workflowstepid
      AND c.qty+NVL(c.alllossqty,0)>NVL(c.workreportnum,0)     
      AND c.mfgordername='{0}' 
      AND c.togetherflag='{1}' 
      AND c.productid='{2}' 
      AND csd.workflowstepid='{3}' 
      AND c.workflowstepid='{3}'
      AND c.factoryid='{4}' ";

        if (jObject["queryType"].ToString() == "待领工")
        {
            sql += " AND csd.recvdate IS NULL ";

        }
        else if (jObject["queryType"].ToString() == "待报工")
        {
            sql += " AND csd.recvdate IS NOT NULL ";
            //sql += string.Format(" AND csd.recvemployeeid = '{0}'", jObject["workerid"].ToString());
        }

        sql += @"
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{5}') OR (csd.workerid IS NULL AND csdd.workerid='{5}')) 
ORDER BY c.containername";
        string mfgordername = jObject["mfgordername"] != null ? jObject["mfgordername"].ToString() : "";
        string togetherflag = jObject["togetherflag"] != null ? jObject["togetherflag"].ToString() : "";
        string productid = jObject["productid"] != null ? jObject["productid"].ToString() : "";
        string workflowstepid = jObject["workflowstepid"] != null ? jObject["workflowstepid"].ToString() : "";
        string factoryid = jObject["factoryid"] != null ? jObject["factoryid"].ToString() : "";
        string workerid = jObject["workerid"] != null ? jObject["workerid"].ToString() : "";
        sql = string.Format(sql, mfgordername, togetherflag, productid, workflowstepid, factoryid, workerid);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);

        if (dt.Rows.Count == 0)
        {
            return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "请求成功" };
        }

        string containeridList = "";

        foreach (DataRow dr in dt.Rows)
        {
            containeridList += string.Format("'{0}',", dr["containerid"].ToString());
        }

        if (containeridList != "")
        {
            containeridList = containeridList.TrimEnd(',');
        }

        // 过滤已试件报工的单件打卡
        sql = @"
SELECT * FROM containerstepworkreport csw 
WHERE csw.isuse = 0 AND csw.workflowstepid='{0}' AND csw.containerid IN ({1}) AND NVL(csw.specimenqty,0)>0";


        sql = string.Format(sql, workflowstepid, containeridList);
        DataTable dtSJ = DatabaseHelper.Query_ReturnDatTable(sql);

        foreach (DataRow dr in dtSJ.Rows)
        {
            foreach (DataRow i in dt.Rows)
            {
                //过滤已试件报工的单件打卡
                if (dr["containerid"].ToString() == i["containerid"].ToString())
                {
                    i.Delete();
                    dt.AcceptChanges();
                    break;
                }
            }
        }

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }

        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询派工及已报工信息(派工数、已报工数、派工人信息)
    uMESProcessResult getDispatchAndReportInfo(JObject jObject)
    {
        string sql = @"
SELECT csd.containerstepdispatchid,csd.qty,NVL(a.reportqty,0) AS reportqty,NVL(a.lossqty,0) AS lossqty,e.fullname,csd.createdate 
FROM containerstepdispatch csd 
LEFT JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid 
LEFT JOIN employee e ON e.employeeid = csd.employeeid --派工人
LEFT JOIN 
(
   SELECT NVL(SUM(csw.qty), 0) reportqty,csw.containerstepdispatchid,NVL(SUM(csw.lossqty), 0) lossqty
   FROM containerstepworkreport csw
   WHERE csw.containerstepdispatchid = '{0}' AND csw.isuse = 0
   GROUP BY csw.containerstepdispatchid
) a ON a.containerstepdispatchid = csd.containerstepdispatchid
WHERE csd.isuse = 0 AND csd.containerstepdispatchid = '{0}' 
      AND ((csd.workerid IS NOT NULL AND csd.workerid = '{1}') OR (csd.workerid IS NULL AND csdd.workerid='{1}'))
";
        string containerstepdispatchid = "", workerid = "";
        if (jObject["containerstepdispatchid"] != null)
        {
            containerstepdispatchid = jObject["containerstepdispatchid"].ToString();
        }
        if (jObject["workerid"] != null)
        {
            workerid = jObject["workerid"].ToString();
        }
        sql = string.Format(sql, containerstepdispatchid, workerid);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询批量带子序号批次
    uMESProcessResult getContainerType3List(JObject jObject)
    {
        string parentcontainerid = "";
        if (jObject["parentcontainerid"] != null)
        {
            parentcontainerid = jObject["parentcontainerid"].ToString();
        }

        //查询子序号批次
        string sql = @"
SELECT c.containerid,c.containername,spr.inputseq 
FROM container c 
LEFT JOIN stepcheckpointresult spr ON c.containerid = spr.containerid
WHERE c.parentcontainerid = '{0}' AND c.status =1 
ORDER BY c.containerid";
        sql = string.Format(sql, parentcontainerid);
        DataTable dtContainer = DatabaseHelper.Query_ReturnDatTable(sql);

        //查询子序号批次中已报过工的数据
        sql = @"
SELECT DISTINCT c.containername,cswc.childcontainerid 
FROM containerstepworkreportchild cswc 
LEFT JOIN containerstepworkreport csw ON csw.containerstepworkreportid = cswc.containerstepworkreportid  AND csw.isuse = 0 
LEFT JOIN containercurrentinfo c ON c.containerid = csw.containerid AND c.workflowstepid = csw.workflowstepid 
WHERE c.containerid = '{0}'";
        sql = string.Format(sql, parentcontainerid);
        DataTable dtReport = DatabaseHelper.Query_ReturnDatTable(sql);

        //子批次号中移除已报工的数据
        foreach (DataRow dr in dtReport.Rows)
        {
            foreach (DataRow i in dtContainer.Rows)
            {
                //过滤子批次中已经报过工的
                if (dr["childcontainerid"].ToString() == i["containerid"].ToString())
                {
                    i.Delete();
                    dtContainer.AcceptChanges();
                    break;
                }
            }
        }

        foreach (DataColumn col in dtContainer.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtContainer, RowCount = dtReport.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询工序设备信息
    uMESProcessResult getResourceList(JObject jObject)
    {
        //派工时指定的设备+工序基础数据绑定的设备
        string sql = @"
SELECT DISTINCT t.resourceid,t.resourcename 
FROM (
  SELECT rd.resourceid,rd.resourcename
  FROM containerstepdispatch csd
  LEFT JOIN resourcedef rd ON rd.resourceid = csd.resourceid
  WHERE csd.isuse = 0 AND csd.containerid = '{0}' AND csd.workflowstepid = '{1}'
  
  UNION ALL 
  
  SELECT rd.resourceid,rd.resourcename
  FROM workflowstep ws 
  LEFT JOIN specbase sb ON sb.specbaseid = ws.specbaseid 
  LEFT JOIN spec s ON s.specid = NVL(sb.revofrcdid,ws.specid) 
  LEFT JOIN specresourceinfo sri ON sri.specid = s.specid
  LEFT JOIN resourcedef rd ON rd.resourceid = sri.resourceid
  WHERE ws.workflowstepid = '{1}' 
) t
WHERE t.resourceid IS NOT NULL";
        string containerid = "", workflowstepid = "";
        if (jObject["containerid"] != null)
        {
            containerid = jObject["containerid"].ToString();
        }
        if (jObject["workflowstepid"] != null)
        {
            workflowstepid = jObject["workflowstepid"].ToString();
        }
        sql = string.Format(sql, containerid, workflowstepid);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询分厂属性
    uMESProcessResult getFactoryUserattributes(JObject jObject)
    {
        string sql = @"SELECT u.userattributename,u.attributevalue FROM userattribute u WHERE u.parentid = '{0}'";
        string factoryid = jObject["factoryid"] != null ? jObject["factoryid"].ToString() : "";
        sql = string.Format(sql, factoryid);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //报工扫卡工区长、班组长
    uMESProcessResult getEmployeeByCardNum(JObject jObject)
    {
        string sql = @"
SELECT e.employeeid,e.employeename,e.fullname,er.rolenames,f.factoryname
FROM employee e
LEFT JOIN sessionvalues sv ON sv.employeeid = e.employeeid
LEFT JOIN factory f ON f.factoryid = sv.factoryid
LEFT JOIN 
(
    SELECT e.employeeid,listagg(r.rolename,'、') WITHIN GROUP (ORDER BY r.rolename) rolenames  
    FROM employeerole er 
    LEFT JOIN employee e ON e.employeeid = er.employeeid  
    LEFT JOIN roledef r ON r.roleid = er.roleid
    WHERE r.rolename NOT LIKE '%Default%' AND r.rolename NOT IN ('SPC','Portal Configuration','Mfg Audit Trail Inquiry','Security Administration','Login')
    GROUP BY e.employeeid  
) er ON er.employeeid = e.employeeid 
WHERE LOWER(e.cardnum) = '{0}' AND sv.factoryid = '{1}'";
        string cardnum = jObject["cardnum"] != null ? jObject["cardnum"].ToString().ToLower() : "";
        string factoryid = jObject["factoryid"] != null ? jObject["factoryid"].ToString() : "";

        sql = string.Format(sql, cardnum, factoryid);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询叶片首件批次号数据
    uMESProcessResult getFirstContainerData(JObject jObject)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();

        string productid = jObject["productid"] != null ? jObject["productid"].ToString() : "";
        string containerid = jObject["containerid"] != null ? jObject["containerid"].ToString() : "";
        string workflowstepid = jObject["workflowstepid"] != null ? jObject["workflowstepid"].ToString() : "";
        string employeeid = jObject["employeeid"] != null ? jObject["employeeid"].ToString() : "";

        para.Add("ProductId", productid);
        para.Add("ContainerId", containerid);
        para.Add("WorkFlowStepId", workflowstepid);
        para.Add("CurrUserId", employeeid);

        DataSet ds = ypContainerBusiness.GetFirstContainerNOInfo(para);
        DataTable newdt = m_Common.GetContainerInfoByPerContianerID(para["ContainerId"]);
        DataTable newdt_ = m_Common.GetContainerStepWorkReportChildInfo(para["ContainerId"]);
        foreach (DataRow r_ in newdt_.Rows)
        {
            foreach (DataRow r in newdt.Rows)
            {
                if (r_["CHILDCONTAINERID"].ToString() == r["CONTAINERID"].ToString())
                {
                    r.Delete();
                    newdt.AcceptChanges();
                    break;
                }
            }
        }
        ds.Tables.Add(newdt);

        foreach (DataTable dt in ds.Tables)
        {
            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }
        }
        return new uMESProcessResult() { ReturnData = ds, RowCount = "1", Code = "200", Message = "请求成功" };
    }

    //保存报工信息
    uMESProcessResult saveWorkReport(JObject jObject)
    {
        try
        {
            uMESProcessResult r = new uMESProcessResult();
            DataTable dt = JsonConvert.DeserializeObject<DataTable>(jObject["reportData"].ToString());
            DataTable dtChildContainer = JsonConvert.DeserializeObject<DataTable>(jObject["childContainerData"].ToString());//子序号批次表格

            Boolean isSelfCheck = m_Common.GetFatoryAttributes(jObject["FactoryID"].ToString(), "自检自分") == "是" ? true : false;//是否自检自分
            /*
             * START
             * 新增特殊过程验证add by zhangrj 20250409
             * ---------*/
            CurrentUserInfo userInfo = m_Common.GetUserInfo(jObject["employeename"].ToString(), "");
            SpecialReportValidDTO srvDto = m_ReportBusiness.ValidSpecialCourseSpecReportByReport(dt, userInfo);
            if (!srvDto.IsValid)//验证是否无效的特殊过程
            {
                r.ReturnData = false;
                r.RowCount = "0";
                r.Code = "500";
                r.Message = srvDto.Message;
                return r;
            }
            /*
             * 验证结束
             * END
             */
            /*------------------
             * START
             * 新增三定卡片验证add by zhangrj 20251011
             * ---------*/
            Tuple<bool, string> resTu = m_ReportBusiness.ValidSpecThreeFixedCardByReport(dt, userInfo);
            if (!resTu.Item1)
            {
                r.ReturnData = false;
                r.RowCount = "0";
                r.Code = "500";
                r.Message = resTu.Item2;
                return r;
            }
            /*
             * 验证结束
             * END
             */
            string ContainerStepDispatchInfoIDs = "";
            string containerIDs_str = "";

            List<string> redis_dispatchIDList = new List<string>();

            bool isOtherWorkerReporting = false;

            foreach (DataRow dr in dt.Rows)
            {
                ContainerStepDispatchInfoIDs += " OR csd.containerstepdispatchid='" + dr["ContainerStepDispatchID"].ToString() + "'";
                containerIDs_str += "'" + dr["ContainerID"].ToString() + "',";
                if (redis.ExistsSet(redis_Lock, dr["ContainerStepDispatchID"].ToString()))
                {
                    isOtherWorkerReporting = true;
                    r = new uMESProcessResult()
                    {
                        ReturnData = false,
                        RowCount = "0",
                        Code = "200",
                        Message = "批次：" + dr["containername"].ToString() + " 正被报工中,请稍后再试"
                    };
                    r.ReturnData = false;
                    r.RowCount = "0";
                    r.Code = "200";
                    r.Message = "批次：" + dr["containername"].ToString() + " 正被报工中,请稍后再试";
                    break;
                }
                else
                {
                    redis_dispatchIDList.Add(dr["ContainerStepDispatchID"].ToString());
                }
            }

            if (isOtherWorkerReporting) { return r; }

            ContainerStepDispatchInfoIDs = ContainerStepDispatchInfoIDs.Substring(3);
            containerIDs_str = containerIDs_str.TrimEnd(',');
            containerIDs_str = containerIDs_str.Trim('\'');

            DataTable dt_ = m_ReportBusiness.GetWorkReportTimeReallyDisReportNum(ContainerStepDispatchInfoIDs);
            if (dt_.Rows.Count < 1)
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "未找到派工记录，请刷新页面后再试" };
            }
            else
            {
                foreach (DataRow dr in dt_.Rows)
                {
                    if (dr["reportqty"].ToString() != jObject["reportedQty"].ToString())
                    {
                        return new uMESProcessResult()
                        {
                            ReturnData = false,
                            RowCount = "0",
                            Code = "200",
                            Message = "勾选的派工记录对应的报工记录数据已更新，请重新查询数据再进行报工"
                        };
                    }
                }
            }

            List<Dictionary<string, string>> dtoList = new List<Dictionary<string, string>>();
            ContainerStepWorkReportDTO DTO = new ContainerStepWorkReportDTO();
            Dictionary<string, string> para = new Dictionary<string, string>();
            int type = 2;
            if (jObject["reportType"].ToString() == "首件")
            {
                type = 1;//首件报工
            }
            if (jObject["reportType"].ToString() == "返修")
            {
                type = 4;//返修件报工
            }

            //报工redis锁
            if (redis_dispatchIDList.Count > 0)
            {
                redis_dispatchIDs = redis_dispatchIDList.Select(u => { return (RedisValue)u; }).ToArray();
                redis.AddSet(redis_Lock, redis_dispatchIDs);
                redis.SetKeyExpiry(redis_Lock, TimeSpan.FromMinutes(20)); // 设定超期时间20分钟
            }

            DTO.WorkerID = jObject["WorkerID"].ToString();//报工人
            DTO.FactoryID = jObject["FactoryID"].ToString();//工人所在的车间
            DTO.WorkCenterID = jObject["WorkCenterID"].ToString();//工人所在的工区
            DTO.TeamID = jObject["TeamID"].ToString();//工人所在的班组
            DTO.FirstContainerNo = jObject["FirstContainerNo"].ToString();//首件批次号
            DTO.KeyProcessBatchNo = jObject["KeyProcessBatchNo"].ToString();//关键过程批次号
            DTO.Note = jObject["Note"].ToString();//报工备注

            string strSelectChecker_ = m_Common.GetFatoryAttributes(DTO.FactoryID, "报工自检");//获取工厂报工是否有自检信息
            if (jObject["INMTQty"].ToString() != "0")
            {
                DTO.Specimenqty = Convert.ToInt32(jObject["INMTQty"].ToString());//试件数
                type = 3; //试验件报工
            }
            if (jObject["INMTLossQty"].ToString() != "0")
            {
                DTO.Specimenlossqty = Convert.ToInt32(jObject["INMTLossQty"].ToString());//试件废票数
            }

            List<object[]> SQLStringList = new List<object[]>();
            string stepworkreportid = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DTO.ContainerID = dt.Rows[i]["containerid"].ToString();//批次
                DTO.WorkflowstepID = dt.Rows[i]["workflowstepid"].ToString();//工序
                DTO.ResourceID = jObject["ResourceID"].ToString();//设备
                DTO.CheckerID = jObject["CheckerID"].ToString();//报工所选检验员

                //自检超差数
                if (jObject["selfCheckDefeatQty"].ToString() != "0")
                {
                    DTO.SelfCheckOutofToleranceQty = Convert.ToInt32(jObject["selfCheckDefeatQty"].ToString());
                }
                else
                {
                    DTO.SelfCheckOutofToleranceQty = 0;
                }

                //自检报废数
                if (jObject["selfCheckLossQty"].ToString() != "0")
                {
                    DTO.SelfCheckLossQty = Convert.ToInt32(jObject["selfCheckLossQty"].ToString());
                }
                else
                {
                    DTO.SelfCheckLossQty = 0;
                }

                if (strSelectChecker_ != "是")
                {
                    DTO.Qty = Convert.ToInt32(jObject["selfCheckPassQty"].ToString());//不是自检报工，报工数就是填写的报工数
                    DTO.SeleCheckQualifiedQty = 0;//自检合格数
                }
                else
                {
                    DTO.SeleCheckQualifiedQty = Convert.ToInt32(jObject["selfCheckPassQty"].ToString());
                    DTO.Qty = DTO.SeleCheckQualifiedQty + DTO.SelfCheckOutofToleranceQty + DTO.SelfCheckLossQty;//报工数为三者之和
                }

                //结余件确认人id
                if (jObject["surPlusEmployeeID"].ToString() != "")
                {
                    DTO.SurplusEmployeeID = jObject["surPlusEmployeeID"].ToString();
                }

                //备注1（数量）
                if (jObject["Qty2"].ToString() != "")
                {
                    DTO.Qty2 = Convert.ToInt32(jObject["Qty2"].ToString());
                }

                //备注2（单位）
                if (jObject["UOM2ID"].ToString() != "")
                {
                    DTO.UOM2ID = jObject["UOM2ID"].ToString();
                }

                DTO.CheckType = type;//检验类型
                DTO.ContainerStepDispatchID = dt.Rows[i]["containerstepdispatchid"].ToString();//派工id
                string contianerstepworkreportid = Guid.NewGuid().ToString();
                DTO.ContainerStepWorkReportID = contianerstepworkreportid;//报工唯一id
                stepworkreportid = contianerstepworkreportid;

                //生成插入报工表sql语句，并添加到List
                SQLStringList.Add(m_ReportBusiness.FillContainerStepWorkReportInfoTrans(DTO, ""));

                para = new Dictionary<string, string>();
                para.Add("type", "2");
                para.Add("WorkerID", DTO.WorkerID);
                para.Add("ContainerStepDispatchID", dt.Rows[i]["containerstepdispatchid"].ToString());

                SQLStringList.Add(m_ReportBusiness.FillReceviceDispatch(para));
                SQLStringList.Add(new object[] { m_ReportBusiness.UpdateStepCheckPointReportId(DTO), null });

                //存入自动检验需要的参数 add by zhangrj 20230608
                if (jObject["factorycode"].ToString() == "604" && isSelfCheck && DTO.SelfCheckLossQty == 0)
                {
                    para.Add("ContainerStepWorkReportID", DTO.ContainerStepWorkReportID);
                    dtoList.Add(para);
                }
            }

            //插入明细表(子序号批次专用逻辑)
            foreach (DataRow row in dtChildContainer.Rows)
            {
                ContainerStepWorkReportChildDTO entity = new ContainerStepWorkReportChildDTO();
                entity.ChildContainerID = row["containerid"].ToString();
                if (String.IsNullOrWhiteSpace(row["selfCheckLossQty"].ToString()))
                {
                    entity.SelfCheckLossQty = "0";
                }
                else
                {
                    entity.SelfCheckLossQty = row["selfCheckLossQty"].ToString();
                }
                entity.ContainerStepWorkReportID = stepworkreportid;
                SQLStringList.Add(m_ReportBusiness.FillContainerStepWorkReportChildInfo(entity));
            }

            //将批次总表检验标识更新，如果是检验序则在服务中填写报工记录后将标识更新add by tianFW 2019年1月3日
            SQLStringList.Add(m_ReportBusiness.FillUpdateStepCheckNum(containerIDs_str, DTO.CheckType == 1 ? 1 : 2));

            if (SQLStringList.Count > 0)
            {
                Boolean isOK = DatabaseHelper.ExecuteSqlTran(SQLStringList);
                if (!isOK)
                {
                    redis.RemoveSet(redis_Lock, redis_dispatchIDs);
                    return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "报工异常" };
                }
            }

            m_ReportBusiness.UpdateWorkReportNum(containerIDs_str);//更新批次当前序的报工数
            m_DispatchObj.UpdateDispatchIsCompleteStatus(ContainerStepDispatchInfoIDs.Replace("csd", "csw")); //更新派工记录是否完工状态

            //如果存在自检自分，则进行自检自分流程
            if (jObject["factorycode"].ToString() == "604" && isSelfCheck && dtoList.Count > 0)
            {
                m_ReportBusiness.SaveSelfCheckReportData(dtoList, userInfo);
            }

            redis.RemoveSet(redis_Lock, redis_dispatchIDs);
            return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = srvDto.IsUnder95Day ? "报工成功，" + srvDto.Message : "报工成功" };
        }
        catch (Exception ex)
        {
            if (redis_dispatchIDs.Count() > 0)
            {
                redis.RemoveSet(redis_Lock, redis_dispatchIDs);
            }
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "报工异常" };
        }
    }

    //保存领工信息
    uMESProcessResult saveReceive(JObject jObject)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(jObject["willBeReceiveData"].ToString());
        /*
         * START
         * 新增特殊过程验证add by zhangrj 20250409
         * ---------*/
        DataTable dtEmp = m_Common.GetEmployeeByEmployeeID(jObject["WorkerID"].ToString());//获取报工人信息
        CurrentUserInfo userInfo = new CurrentUserInfo()
        {
            EmployeeID = jObject["WorkerID"].ToString(),
            EmployeeName = dtEmp.Rows[0]["EmployeeName"].ToString(),
            FactoryID = dtEmp.Rows[0]["orgfactoryid"].ToString(),
            FullName = dtEmp.Rows[0]["FullName"].ToString()
        };
        SpecialReportValidDTO srvDto = m_ReportBusiness.ValidSpecialCourseSpecReportByReport(dt, userInfo);
        if (!srvDto.IsValid)//验证是否无效的特殊过程
        {
            return new uMESProcessResult() { ReturnData = -1, RowCount = "0", Code = "500", Message = srvDto.Message };
        }
        /*
         * 验证结束
         * END
         */
        /*------------------
        * START
        * 新增三定卡片验证add by zhangrj 20251011
        * ---------*/
        Tuple<bool, string> resTu = m_ReportBusiness.ValidSpecThreeFixedCardByReport(dt, userInfo);
        if (!resTu.Item1)
        {
            return new uMESProcessResult() { ReturnData = -1, RowCount = "0", Code = "500", Message = resTu.Item2 };
        }
        /*
         * 验证结束
         * END
         */
        /*------------------
        * START
        * 新增工序是否排产超期验证add by zhangrj 20251112
        * ---------*/
        Tuple<bool, string> resOv = m_ReportBusiness.IsApsOverTimeByReport(dt);
        if (resOv.Item1)
        {
            return new uMESProcessResult() { ReturnData = -1, RowCount = "0", Code = "500", Message = resOv.Item2 };
        }
        /*
         * 验证结束
         * END
         */
        string containerstepdispatchids = "";
        foreach (DataRow dr in dt.Rows)
        {
            if (containerstepdispatchids == "")
            {
                containerstepdispatchids += string.Format("'{0}'", dr["containerstepdispatchid"].ToString());
            }
            else
            {
                containerstepdispatchids += string.Format(",'{0}'", dr["containerstepdispatchid"].ToString());
            }
        }

        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("type", "1");
        para.Add("ContainerStepDispatchIDs", containerstepdispatchids);
        para.Add("WorkerID", jObject["WorkerID"].ToString());

        // 更新派工表信息
        int rows = m_ReportBusiness.ReceviceDispatch(para);
        string msg = rows > 0 ? "领工成功" : "领工失败";
        return new uMESProcessResult() { ReturnData = rows, RowCount = "0", Code = "200", Message = srvDto.IsUnder95Day ? msg + "，" + srvDto.Message : msg };
    }

    //扫卡
    uMESProcessResult getScanContainerData(JObject jObject)
    {
        string scanStr = jObject["searchText"].ToString();
        string ContainerName = "";
        string scanContainerName = m_Common.GetScanContainerInfoReturnData(ref scanStr, ref ContainerName);
        if (scanContainerName == "")
        {
            return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "未找到相关输入查询批次信息" };
        }
        else
        {
            string ContainerType = scanStr.Split(',')[0].ToString();
            string WorkflowStepID = scanStr.Split(',')[1].ToString();

            DataTable dt = new DataTable();
            dt.Columns.Add("containername");
            dt.Columns.Add("togetherflag");
            dt.Columns.Add("containertype");
            dt.Columns.Add("workflowstepid");

            DataRow dr = dt.NewRow();
            dr["containername"] = ContainerName;
            dr["togetherflag"] = scanContainerName;
            dr["containertype"] = ContainerType;
            dr["workflowstepid"] = WorkflowStepID;

            dt.Rows.Add(dr);
            return new uMESProcessResult() { ReturnData = dt, RowCount = "1", Code = "200", Message = "请求成功" };
        }
    }

    //查询工艺查看Tree数据
    uMESProcessResult getDocumentViewTreeData(JObject jObject)
    {
        DataTable workflowStepDt = m_Common.GetWorkFlowSetpsByWorkflowID(jObject["workflowid"].ToString());
        DataTable workflowDt = m_Common.GetWorkflowInfobyWorkflowID(jObject["workflowid"].ToString());
        DataTable productDt = m_Common.GetProductInfoByID(jObject["productid"].ToString());

        string productInfo = string.Format("{0}:{1}:{2}", productDt.Rows[0]["productname"].ToString(), productDt.Rows[0]["productrevision"].ToString(), productDt.Rows[0]["description"].ToString());
        string workflowInfo = string.Format("{0}:{1}", workflowDt.Rows[0]["workflowname"].ToString(), workflowDt.Rows[0]["workflowrevision"].ToString());

        DataTable dt = new DataTable();
        dt.Columns.Add("id");
        dt.Columns.Add("label");
        dt.Columns.Add("parentid");
        dt.Columns.Add("type");

        DataRow dr = dt.NewRow();
        dr["id"] = productDt.Rows[0]["productid"].ToString();
        dr["label"] = productInfo;
        dr["parentid"] = "0";
        dr["type"] = "product";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr["id"] = workflowDt.Rows[0]["WORKFLOWID"].ToString();
        dr["label"] = workflowInfo;
        dr["parentid"] = productDt.Rows[0]["productid"].ToString();
        dr["type"] = "workflow";

        dt.Rows.Add(dr);

        foreach (DataRow row in workflowStepDt.Rows)
        {
            dr = dt.NewRow();
            dr["id"] = string.Format("{0}-{1}", row["WORKFLOWSTEPID"].ToString(), row["SPECID"].ToString());
            dr["label"] = row["WORKFLOWSTEPNAME"].ToString();
            dr["parentid"] = workflowDt.Rows[0]["WORKFLOWID"].ToString();
            dr["type"] = "spec";
            dt.Rows.Add(dr);
        }

        PageObjectTree t = new PageObjectTree();
        List<PageObjectTree> treeNodes = new List<PageObjectTree>();
        treeNodes = t.BindTree(dt, null, "0");
        return new uMESProcessResult() { ReturnData = treeNodes, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询文档列表
    uMESProcessResult getDocumentList(JObject jObject)
    {
        string nodeType = jObject["nodeType"].ToString();
        DataTable dt = new DataTable();
        switch (nodeType)
        {
            case "spec":
                dt = m_DocViewObj.GetObjectDoc("Spec", jObject["id"].ToString());
                break;
            case "workflow":
                dt = m_DocViewObj.GetObjectDoc("Workflow", jObject["id"].ToString());
                break;
            case "product":
                dt = m_DocViewObj.GetObjectDoc("Product", jObject["id"].ToString());
                break;
            default:
                break;
        }

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    uMESProcessResult getDownloadUrl(JObject jObject)
    {
        string url = "";
        String FilePath = jObject["filepath"].ToString();
        try
        {
            string remoteUrl = string.Empty;
            if (FilePath.Contains("MESUpload/")) //新增排故工艺附件判断 add by zhangrj 20250722
            {
                remoteUrl = string.Format("http://10.15.7.76/{0}", FilePath);
            }
            else
            {
                remoteUrl = "http://10.15.7.76/MesFiles/" + HttpUtility.UrlEncode(FilePath.Replace("Temp/", "")).Replace("+", "%20");
            }
            WebRequest req = WebRequest.Create(remoteUrl);
            req.Timeout = 2000;
            WebResponse res = req.GetResponse();
            url = remoteUrl;
            res.Close();
        }
        catch (WebException webExcp) { }

        if (url == "")
        {
            try
            {
                var remoteUrl = "http://10.15.7.75/InSiteWebApplication/" + HttpUtility.UrlEncode(FilePath).Replace("+", "%20");
                WebRequest req = WebRequest.Create(remoteUrl);
                req.Timeout = 2000;
                WebResponse res = req.GetResponse();
                url = remoteUrl;
                res.Close();
            }
            catch (WebException webExcp) { }
        }

        if (url == "")
        {
            try
            {
                var remoteUrl = "http://localhost/InSiteWebApplication/" + HttpUtility.UrlEncode(FilePath).Replace("+", "%20");
                WebRequest req = WebRequest.Create(remoteUrl);
                req.Timeout = 2000;
                WebResponse res = req.GetResponse();
                url = remoteUrl;
                res.Close();
            }
            catch (WebException webExcp) { }
        }
        return new uMESProcessResult() { ReturnData = url, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    uMESProcessResult getMESFeedBackData(JObject jObject)
    {
        string sql = @"
SELECT cci.workflowname,cci.workflowrevision,cci.specname,cci.familylistnames
FROM containercurrentinfo cci
WHERE cci.containerid = '{0}'";
        sql = string.Format(sql, jObject["containerid"].ToString());
        DataTable dtContainerInfo = DatabaseHelper.Query_ReturnDatTable(sql);

        string workflowname = "", workflowrevision = "", familylistnames = "", specname = "";
        if (dtContainerInfo.Rows.Count > 0)
        {
            workflowname = dtContainerInfo.Rows[0]["workflowname"].ToString();
            workflowrevision = dtContainerInfo.Rows[0]["workflowrevision"].ToString();
            familylistnames = dtContainerInfo.Rows[0]["familylistnames"].ToString();
            specname = dtContainerInfo.Rows[0]["specname"].ToString();
        }

        //插入前先删除当前用户的历史数据
        string strDeleteSql = string.Format("DELETE bpm_containerinfo t WHERE t.createuser = '{0}'", jObject["createuser"].ToString());
        DatabaseHelper.ExecuteSql(strDeleteSql);

        //插入数据
        string strInsertSql = @"
INSERT INTO bpm_containerinfo(createuser,createdate,productname,togetherflag,workflowstepname,specname,specno,familylistnames,workflowname,workflowrevision,resourcename)
VALUES('{0}',SYSDATE,'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";
        strInsertSql = String.Format(strInsertSql,
            jObject["createuser"].ToString(),
            jObject["productname"].ToString(),
            jObject["togetherflag"].ToString(),
            jObject["workflowstepname"].ToString(),
            specname,
            jObject["specno"].ToString(),
            familylistnames,
            workflowname,
            workflowrevision,
            jObject["resourcename"].ToString());
        DatabaseHelper.ExecuteSql(strInsertSql);
        return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //领工校验
    uMESProcessResult checkReceiveData(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["willBeReceiveData"].ToString());
        string msg = "校验成功";

        bool checkResult = true;
        foreach (DataRow dr in dt.Rows)
        {
            string sql = @"
SELECT csd.recvdate,csd.recvemployeeid 
FROM containerstepdispatch csd 
WHERE csd.recvemployeeid IS NOT NULL AND csd.containerstepdispatchid = '{0}'";
            sql = string.Format(sql, dr["containerstepdispatchid"].ToString());

            DataTable dtReceive = DatabaseHelper.Query_ReturnDatTable(sql);

            if (dtReceive.Rows.Count > 0)
            {
                msg = "批次:【" + dr["containername"] + "】已领工";
                checkResult = false;
                break;
            }
        }
        return new uMESProcessResult() { ReturnData = checkResult, RowCount = "0", Code = "200", Message = msg };
    }

    //报工校验
    uMESProcessResult checkReportData(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["reportData"].ToString());
        string msg = "请求成功";

        //1.验证批次是否存在暂停
        bool isHold = false;
        foreach (DataRow dr in dt.Rows)
        {
            if (m_Common.JudeContainerHold(dr["containerid"].ToString(), ref msg))
            {
                msg = "批次:【" + dr["containername"] + "】已暂停，暂停原因：" + msg;
                isHold = true;
                break;
            }
        }

        if (isHold)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
        }

        //2.校验槽液化验是否过期
        if (!bath.IsVaildResMonitorCheck(obj["resourceid"].ToString()))
        {
            msg = "设备:【" + obj["resourcename"].ToString() + "】槽液化验到期，请重新提交检测";
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
        }

        //3.工装自检自分验证
        if (m_Common.GetFatoryAttributes(obj["factoryid"].ToString(), "自检自分") == "是")
        {
            bool isFirst = obj["reportType"].ToString() == "首件";
            if (!m_ReportBusiness.IsValidSelfCheckReport(dt, isFirst))
            {
                msg = isFirst ? "专检序已存在首件检验" : "专检序派工数量大于2，需要进行首件检验";
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
            }
        }

        //4.验证是否存在报工完的数据
        bool isFinish = false;
        string sql = @"
SELECT 1 FROM 
(
    SELECT SUM(NVL(csw.qty,0)) reportqty,c.qty,SUM(NVL(csw.lossqty,0)) lossqty
    FROM containerstepworkreport csw 
    LEFT JOIN containercurrentinfo c ON c.containerid = csw.containerid 
    WHERE csw.containerid = '{0}' AND csw.workflowstepid = '{1}' AND csw.isuse = 0 
    GROUP BY csw.containerid,csw.workflowstepid,c.qty
) k WHERE k.reportqty >= k.qty + k.lossqty";

        foreach (DataRow dr in dt.Rows)
        {
            sql = string.Format(sql, dr["containerid"].ToString(), dr["workflowstepid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                msg = "批次：【" + dr["containername"].ToString() + "】已报工，不能重复报工";
                isFinish = true;
            }
        }

        if (isFinish)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
        }

        //5.验证是否存在相同热处理炉号的其他先锋批次未合并 add by zhangrj 20231114
        if (obj["factorycode"].ToString() == "608")
        {
            if (Convert.ToBoolean(ypContainerBusiness.IsExistsProductBatchNoXFContainer(dt, ref msg)))
            {
                return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = msg };
            }
        }

        //6.验证关键过程检测项是否录完(数量批没有这个限制)
        uMESProcessResult res = m_ContainerObj.JudgeContainerCheckPoint(dt);
        if (!res.Result)
        {
            return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = res.Message };
        }

        return new uMESProcessResult() { ReturnData = true, RowCount = "0", Code = "200", Message = msg };
    }

    // 查询人员排班信息
    uMESProcessResult getEmployeeWorkdate(JObject obj)
    {
        string sql = @"
SELECT 'today' datatype,a.fullname,a.employeeid,a.workdate,s.workshiftname,
       to_char(a.workdate,'yyyy/mm/dd') || ' ' || s.startdate startdate,
       to_char(a.workdate,'yyyy/mm/dd') || ' ' || s.enddate enddate
FROM apsemployeeworkdate a
LEFT JOIN workshift s ON a.workshiftid = s.workshiftid
WHERE a.employeeid = '{0}' AND a.workdate = TRUNC(SYSDATE)

UNION ALL 

SELECT 'tomorrow' datatype,a.fullname,a.employeeid,a.workdate,s.workshiftname,
       to_char(a.workdate,'yyyy/mm/dd') || ' ' || s.startdate startdate,
       to_char(a.workdate,'yyyy/mm/dd') || ' ' || s.enddate enddate
FROM apsemployeeworkdate a
LEFT JOIN workshift s ON a.workshiftid = s.workshiftid
WHERE a.employeeid = '{0}' AND a.workdate = TRUNC(SYSDATE) + 1";

        sql = string.Format(sql, obj["employeeid"].ToString());

        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询员工工时
    uMESProcessResult getWorkerWorkTime(JObject obj)
    {
        string worktime = "0";
        if (obj["day"].ToString() == "1")
        {
            return new uMESProcessResult() { ReturnData = worktime, RowCount = "0", Code = "200", Message = "请求成功" };
        }

        string sql = "SELECT t.worktime FROM r_employeeworktime@mesreport t WHERE t.employeeid = '{0}'";
        sql = string.Format(sql, obj["employeeid"].ToString());
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);

        if (dt.Rows.Count > 0)
        {
            worktime = dt.Rows[0]["worktime"].ToString();
        }
        return new uMESProcessResult() { ReturnData = worktime, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询超越单信息
    uMESProcessResult getSurpassbillInfoList(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["reportData"].ToString());
        DataTable dtWorkflow = m_Common.GetWorkFlowNameByWorkFLowID(dt.Rows[0]["workflowid"].ToString());
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("ProductName", dt.Rows[0]["productname"].ToString());
        para.Add("ProcessNo", dtWorkflow.Rows[0]["process_No"].ToString());
        para.Add("ContainerID", "");

        string containerids = "";
        foreach (DataRow dr in dt.Rows)
        {
            containerids += string.Format("'{0}',", dr["containerid"].ToString());
        }

        if (!String.IsNullOrWhiteSpace(containerids))
        {
            para["ContainerID"] = containerids.TrimEnd(',').ToString();
        }
        DataTable dtSurpassBill = m_Common.QuerySurpassBillInfo(para);

        if (dtSurpassBill.Rows.Count == 0)
        {
            return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "所选批次无超越单" };
        }

        foreach (DataColumn col in dtSurpassBill.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtSurpassBill, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    // 查询超越单附件信息
    uMESProcessResult getSurpassbillDocList(JObject obj)
    {
        DataTable postData = JsonConvert.DeserializeObject<DataTable>(obj["postData"].ToString());
        string surpassBillInfoIDs = "";
        foreach (DataRow dr in postData.Rows)
        {
            surpassBillInfoIDs += string.Format("'{0}',", dr["surpassbillinfoid"].ToString());
        }

        if (!String.IsNullOrWhiteSpace(surpassBillInfoIDs))
        {
            surpassBillInfoIDs = surpassBillInfoIDs.TrimEnd(',');
        }

        string sql = @"
SELECT sap.accessoriespath,sbi.*
FROM surpassaccessoriespath sap
LEFT JOIN surpassbillinfo sbi ON sbi.surpassbillinfoid=sap.surpassbillinfoid
WHERE sap.surpassbillinfoid in ({0})";

        sql = string.Format(sql, surpassBillInfoIDs);
        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询用户绑定的设备列表
    uMESProcessResult getResourceStatusListData(JObject obj)
    {
        DataTable dt = m_Common.GetResourceDefByemployeeid(string.Format("em.employeeid='{0}'", obj["employeeid"].ToString()));

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //保存设备状态录入数据
    uMESProcessResult setResourceStatus(JObject obj)
    {
        DataTable postData = JsonConvert.DeserializeObject<DataTable>(obj["postData"].ToString());
        bool isSuccess = m_ReportBusiness.AddWorkResourceStatusInfo(postData);
        return new uMESProcessResult() { ReturnData = isSuccess, RowCount = "0", Code = "200", Message = "请求成功" };
    }

    //查询集件信息
    uMESProcessResult getCollectInfo(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["postData"].ToString());
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("BomID", dt.Rows[0]["bomid"].ToString());
        dic.Add("ContainerID", dt.Rows[0]["containerid"].ToString());
        dic.Add("WorkFlowID", dt.Rows[0]["workflowid"].ToString());
        dic.Add("Sequence", dt.Rows[0]["sequence"].ToString());
        dic.Add("IsCurrentStep", "1");

        DataTable dtCollectInfo = m_issueData.GetCollectPieceManageBOMList(dic);

        foreach (DataColumn col in dtCollectInfo.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtCollectInfo, RowCount = dtCollectInfo.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询待检验数据
    uMESProcessResult getUnCheckData(JObject obj)
    {
        string sql = @"
SELECT c.productname,c.productid,c.workflowstepname,c.workflowstepid,c.specno, c.workflowid,c.workflowstepsequence AS SEQUENCE,c.togetherflag, 
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,c.mfgordername,c.planqty,
       c.factoryid,(c.productname||'/'||c.containerno) productbatch,c.containerno,
       SUM(c.qty) AS wipqty ,'' containerid,''containername,'' facontianerid,'' ishold
FROM containercurrentinfo c
LEFT JOIN 
(
     SELECT csw.containerid,csw.workflowstepid,SUM(csw.qty) AS nocheckreportqty 
     FROM containerstepworkreport csw
     LEFT JOIN containercheckinfo cci ON cci.containerstepworkreportid = csw.containerstepworkreportid AND cci.isuse = 0
     WHERE csw.isuse = 0 AND NVL(csw.lossqty,0) = 0 
           AND cci.containercheckinfoid IS NULL 
           AND csw.workerid='{0}'
           AND csw.containerfinishedcheckinfoid IS NULL
     GROUP BY csw.containerid,csw.workflowstepid
) a ON  a.containerid = c.containerid AND a.workflowstepid = c.workflowstepid
WHERE c.dispatchnum = 1 AND c.isinstore=0 AND c.splitnum = 0 AND c.factoryid='{1}' 
      AND NVL(c.nonconformingnum,0) <> 1 
      AND c.containerstatus=1 AND a.containerid IS NOT NULL
      AND c.containertype='7' {2} ";

        if (obj["productname"] != null && obj["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", obj["productname"].ToString());
        }

        if (obj["mfgordername"] != null && obj["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", obj["mfgordername"].ToString());
        }
        
        sql += @"
GROUP BY c.productid, c.productname, c.workflowstepname,c.workflowstepid, c.workflowid, c.workflowstepsequence, c.specno,
         c.togetherflag, c.containertype,c.mfgordername,c.planqty,c.factoryid,c.workflowroute,c.containerno

UNION ALL

SELECT c.productname,c.productid,c.workflowstepname,c.workflowstepid,c.specno, c.workflowid,c.workflowstepsequence AS SEQUENCE,c.togetherflag, 
       c.containertype,DECODE(c.containertype,2,'批量加工',3,'批量带子序号', 7,'单件加工') AS containertypename,c.mfgordername,c.planqty,
       c.factoryid,(c.productname||'/'||c.containerno) productbatch,c.containerno,
       c.qty AS wipqty , c.containerid,c.containername,c.containerid AS facontianerid,c.ishold
FROM containercurrentinfo c
LEFT JOIN 
(
     SELECT csw.containerid,csw.workflowstepid,SUM(csw.qty) AS nocheckreportqty 
     FROM containerstepworkreport csw
     LEFT JOIN containercheckinfo cci ON cci.containerstepworkreportid = csw.containerstepworkreportid AND cci.isuse = 0
     WHERE csw.isuse = 0 AND NVL(csw.lossqty,0) = 0 
           AND cci.containercheckinfoid IS NULL 
           AND csw.workerid='{0}' 
           AND csw.containerfinishedcheckinfoid IS NULL 
     GROUP BY csw.containerid,csw.workflowstepid
) a ON  a.containerid = c.containerid AND a.workflowstepid = c.workflowstepid
WHERE c.dispatchnum = 1 AND c.isinstore=0 AND c.splitnum = 0 AND c.factoryid='{1}' 
      AND NVL(c.nonconformingnum,0) <> 1
      {2}
      AND c.containerstatus=1 AND a.containerid IS NOT NULL
      AND c.containertype<>'7'";

        string containername = "";
        if (obj["togetherflag"] != null && obj["togetherflag"].ToString() != "")
        {
            containername = string.Format(" AND c.togetherflag = '{0}'", obj["togetherflag"].ToString());
        }

        if (obj["productname"] != null && obj["productname"].ToString() != "")
        {
            sql += string.Format(" AND c.productname LIKE '%{0}%'", obj["productname"].ToString());
        }

        if (obj["mfgordername"] != null && obj["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND c.mfgordername LIKE '%{0}%'", obj["mfgordername"].ToString());
        }

        sql = string.Format(sql, obj["workerid"].ToString(), obj["factoryid"].ToString(), containername);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询待检验明细数据
    uMESProcessResult getUnCheckDetailInfo(JObject obj)
    {
        string sql = @"
SELECT c.containerid
FROM containercurrentinfo c
LEFT JOIN (
     SELECT csw.containerid,csw.workflowstepid,SUM(csw.qty) AS nocheckreportqty 
     FROM containerstepworkreport csw
     LEFT JOIN containercheckinfo cci ON cci.containerstepworkreportid = csw.containerstepworkreportid AND cci.isuse = 0
     WHERE csw.isuse = 0 AND NVL(csw.lossqty,0) = 0 AND cci.containercheckinfoid IS NULL 
           AND csw.workerid='{0}' 
           AND csw.containerfinishedcheckinfoid IS NULL 
     GROUP BY csw.containerid,csw.workflowstepid
) a ON a.containerid = c.containerid AND a.workflowstepid = c.workflowstepid
WHERE c.dispatchnum = 1 AND c.isinstore=0 AND c.splitnum = 0 AND c.factoryid='{1}' 
      AND NVL(c.nonconformingnum,0) <> 1 AND c.containerstatus=1 AND a.containerid IS NOT NULL
      AND c.mfgordername = '{2}'  AND c.togetherflag = '{3}'  
      AND c.productid = '{4}'  
      AND c.workflowstepid = '{5}'";

        string workerid = obj["workerid"].ToString();
        string factoryid = obj["factoryid"].ToString();
        string mfgordername = obj["mfgordername"].ToString();
        string togetherflag = obj["productbatch"].ToString();
        string productid = obj["productid"].ToString();
        string workflowstepid = obj["workflowstepid"].ToString();

        sql = string.Format(sql, workerid, factoryid, mfgordername, togetherflag, productid, workflowstepid);

        DataTable dtContainer = DatabaseHelper.Query_ReturnDatTable(sql);

        if (dtContainer.Rows.Count == 0)
        {
            return new uMESProcessResult() { ReturnData = null, RowCount = "0", Code = "200", Message = "请求成功" };
        }

        string containerids = "";
        foreach (DataRow dr in dtContainer.Rows)
        {
            containerids += string.Format("csw.containerid='{0}' OR ", dr["containerid"].ToString());
        }
        containerids = containerids.Substring(0, containerids.Length - 3);
        containerids = string.Format("({0})", containerids);

        sql = @"
SELECT csw.containerstepworkreportid,csw.createdate reportdate,csw.qty reportqty,
       DECODE(csw.checktype,1,'首件',2,'其他',3,'试件',4,'返件',20,'自动',25,'下料报') checktype,
       em.fullname workername,c.containername,csw.containerid,csw.specimenqty,csw.specimenlossqty,csw.containerstepdispatchid,
       em2.fullname checkername,NVL(curr.ishold,0) ishold,csw.workflowstepid,
       curr.workflowstepname,curr.productdescription,
       csd.plannedstartdate,csd.plannedfinishdate,csd.createdate dispatchdate,e3.fullname dispatchemp,csd.qty dispatchqty,
       csd.recvdate,e4.fullname recvemp
FROM containerstepworkreport csw 
LEFT JOIN employee em ON em.employeeid = csw.workerid
LEFT JOIN container c ON c.containerid = csw.containerid
LEFT JOIN employee em2 ON em2.employeeid = csw.checkerid
LEFT JOIN containercheckinfo cci ON cci.containerstepworkreportid = csw.containerstepworkreportid AND cci.isuse=0
LEFT JOIN containercurrentinfo curr ON curr.containerid = csw.containerid
LEFT JOIN containerstepdispatch csd ON csd.containerstepdispatchid = csw.containerstepdispatchid
LEFT JOIN employee e3 ON e3.employeeid = csd.employeeid
LEFT JOIN employee e4 ON e4.employeeid = csd.recvemployeeid
WHERE cci.containercheckinfoid IS NULL AND csw.isuse = 0 AND {0}
      AND csw.workflowstepid='{1}' AND csw.workerid='{2}' AND csw.containerfinishedcheckinfoid IS NULL 
ORDER BY csw.createdate DESC,csw.containerid";

        sql = string.Format(sql, containerids, workflowstepid, workerid);

        DataTable dtResult = DatabaseHelper.Query_ReturnDatTable(sql);

        foreach (DataColumn col in dtResult.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dtResult, RowCount = dtResult.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //撤销领工
    uMESProcessResult revokeReceiveData(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["willBeRevokeReceiveData"].ToString());
        string containerstepdispatchids = "";
        foreach (DataRow dr in dt.Rows)
        {
            if (containerstepdispatchids == "")
            {
                containerstepdispatchids += string.Format("'{0}'", dr["containerstepdispatchid"].ToString());
            }
            else
            {
                containerstepdispatchids += string.Format(",'{0}'", dr["containerstepdispatchid"].ToString());
            }
        }

        string sql = @"UPDATE containerstepdispatch csd SET csd.recvdate = NULL,csd.recvemployeeid = NULL WHERE csd.containerstepdispatchid IN ({0})";
        sql = string.Format(sql, containerstepdispatchids);

        int rows = DatabaseHelper.ExecuteSql(sql);
        string msg = rows > 0 ? "领工撤销成功" : "领工撤销失败";
        return new uMESProcessResult() { ReturnData = rows, RowCount = "0", Code = "200", Message = msg };
    }

    //撤销报工
    uMESProcessResult revokeReportData(JObject obj)
    {
        DataTable dt = JsonConvert.DeserializeObject<DataTable>(obj["willBeRevokeReportData"].ToString());
        string ContainerStepWorkReportIDs = "";
        string ContainerStepDispatchInfoIDs = "";
        string ContainerIDs = "";
        int delcount = 0;

        List<Dictionary<string, string>> conList = new List<Dictionary<string, string>>();

        DataTable dtFirstContainerIDs = new DataTable();//记录需要撤销的报工对应的首检批次 add by zhangrj 20220712
        dtFirstContainerIDs.Columns.Add("ContainerId");

        foreach (DataRow dr in dt.Rows)
        {
            string sql = @"SELECT csw.containerid FROM containerstepworkreport csw WHERE csw.containerstepworkreportid = '{0}' AND csw.isuse = 0";
            sql = string.Format(sql, dr["containerstepworkreportid"].ToString());
            if (DatabaseHelper.Query_ReturnDatTable(sql).Rows.Count == 0)
            {
                return new uMESProcessResult()
                {
                    ReturnData = false,
                    RowCount = "0",
                    Code = "200",
                    Message = string.Format("批次:【{0}】已撤销报工，请刷新后再试", dr["containername"].ToString())
                };
            }

            bool isCombine = m_ContainerObj.IsCombinateContainer(dr["containerid"].ToString());
            if (isCombine)
            {
                return new uMESProcessResult()
                {
                    ReturnData = false,
                    RowCount = "0",
                    Code = "200",
                    Message = string.Format("批次:【{0}】已合卡，不能撤销报工", dr["containername"].ToString())
                };
            }

            //如果撤销首检，记录批次ID add by zhangrj 20220712
            if (dr["checktype"].ToString() == "首件")
            {
                DataRow row = dtFirstContainerIDs.NewRow();
                row["ContainerId"] = dr["containerid"].ToString();
            }

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("CONTAINERID", dr["containerid"].ToString());
            dic.Add("WORKFLOWSTEPID", dr["workflowstepid"].ToString());

            if (!conList.Contains(dic))
            {
                conList.Add(dic);
            }

            if (!ContainerIDs.Contains(dr["containerid"].ToString()))
            {
                ContainerIDs += "," + dr["containerid"].ToString();
            }

            if (ContainerStepWorkReportIDs == "")
            {
                ContainerStepWorkReportIDs = string.Format("'{0}'", dr["containerstepworkreportid"].ToString());
            }
            else
            {
                ContainerStepWorkReportIDs += string.Format(" OR CSW.CONTAINERSTEPWORKREPORTID ='{0}'", dr["containerstepworkreportid"].ToString());
            }

            ContainerStepDispatchInfoIDs += string.Format(" OR csw.containerstepdispatchid='{0}'", dr["containerstepdispatchid"].ToString());
            delcount += 1;
        }

        ContainerStepDispatchInfoIDs = ContainerStepDispatchInfoIDs.Substring(3);
        ContainerIDs = ContainerIDs.Substring(1).Replace(",", "','");

        if (m_ReportBusiness.DelContainerStepWorkReportInfoBycswrid(ContainerStepWorkReportIDs))
        {
            m_DispatchObj.UpdateDispatchIsCompleteStatus(ContainerStepDispatchInfoIDs); //更新派工记录是否完工标识
            m_ReportBusiness.UpdateWorkReportNum(ContainerIDs);//更新批次总表当前序报工总数
            LogHelp.WriteOrcale(String.Format("报工撤销@^批次：{0}报工撤销成功@^工序ID:{1}报工ID:{2}@^{3}@^{4}",
                                              ContainerIDs,
                                              dt.Rows[0]["workflowstepid"].ToString(),
                                              ContainerStepWorkReportIDs,
                                              Convert.ToString(Guid.NewGuid()),
                                              obj["employeename"].ToString())); //'写入数据库 
            m_ReportBusiness.DelContainerStepInfoReport2BySpec(conList);//删除工步
            //删除检验待处理状态
            foreach (var item in conList)
            {
                string sql = "UPDATE containerchecksuspending css SET css.isuse=1 WHERE css.containerid='{0}' AND css.workflowstepid='{1}'";
                sql = string.Format(sql, item["CONTAINERID"], item["WORKFLOWSTEPID"]);
                DatabaseHelper.ExecuteSql(sql);
            }

            //新增更新总表的FirstCheckNum字段为无 add by zhangrj 20220712
            dtFirstContainerIDs = dtFirstContainerIDs.DefaultView.ToTable(true, "ContainerId");
            foreach (DataRow dr in dtFirstContainerIDs.Rows)
            {
                Dictionary<string, string> updatePara = new Dictionary<string, string>();
                Dictionary<string, string> conditionPara = new Dictionary<string, string>();
                conditionPara["ContainerId"] = "'" + dr["ContainerId"].ToString() + "'";
                updatePara["firstchecknum"] = "0";
                m_ConCurrentinfoObj.UpdateContainerCurrentInfoByField(updatePara, conditionPara);
            }

            return new uMESProcessResult() { ReturnData = true, RowCount = delcount.ToString(), Code = "200", Message = "报工撤销成功" };
        }
        return new uMESProcessResult() { ReturnData = false, RowCount = "0", Code = "200", Message = "报工撤销失败" };
    }

    //撤销领工校验
    uMESProcessResult checkReceiveStatus(JObject obj)
    {
        DataTable dtPostData = JsonConvert.DeserializeObject<DataTable>(obj["willBeRevokeReceiveData"].ToString());
        string containerstepdispatchids = "";
        foreach (DataRow dr in dtPostData.Rows)
        {
            if (containerstepdispatchids == "")
            {
                containerstepdispatchids += string.Format("'{0}'", dr["containerstepdispatchid"].ToString());
            }
            else
            {
                containerstepdispatchids += string.Format(",'{0}'", dr["containerstepdispatchid"].ToString());
            }
        }

        string sql = @"
SELECT csw.containerstepworkreportid,csw.qty,csw.createdate
FROM containerstepdispatch csd
LEFT JOIN containercurrentinfo cci ON cci.containerid = csd.containerid
INNER JOIN containerstepworkreport csw ON csw.containerstepdispatchid = csd.containerstepdispatchid AND csw.isuse = 0
WHERE csd.containerstepdispatchid IN ({0}) ";
        sql = string.Format(sql, containerstepdispatchids);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询已派工未报工工序sql
    string getUnReportWorkflowStepCountSql(JObject obj)
    {
        string sql = @"
--查询只派工给一个人的情况
SELECT cci.mfgordername,f.factoryname,w.workcentername,t.teamname,rd.resourcename,rd.description resourcedesc,
       cci.containername,ws.workflowstepname,cci.workflowstepname currentspec,csd.plannedstartdate,csd.plannedfinishdate,csd.qty,
       e.fullname receiver,csd.recvdate,'{0}' worker,
       CASE WHEN csd.recvemployeeid IS NULL THEN '未领工'
            WHEN csd.recvemployeeid IS NOT NULL THEN '未报工'
       END status,
       CASE WHEN cci.workflowstepid = csd.workflowstepid AND csd.recvemployeeid IS NULL THEN '是' ELSE '否' END receivestate,
       CASE WHEN cci.workflowstepid = csd.workflowstepid AND csd.recvemployeeid IS NOT NULL AND NVL(csd.iscomplete,0) = 0 THEN '是' ELSE '否' END reportstate
FROM containercurrentinfo cci
INNER JOIN containerstepdispatch csd ON csd.containerid = cci.containerid
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN team t ON t.teamid = csd.teamid
LEFT JOIN workcenter w ON w.workcenterid = csd.workcenterid
LEFT JOIN employee e ON e.employeeid =  csd.recvemployeeid
LEFT JOIN employee e2 ON e2.employeeid = csd.workerid
LEFT JOIN factory f ON f.factoryid = csd.factoryid
LEFT JOIN resourcedef rd ON rd.resourceid = csd.resourceid
WHERE cci.isinstore = 0 AND cci.containerstatus = 1 AND csd.isuse = 0 AND NVL(csd.iscomplete,0) = 0
      AND csd.factoryid = '{1}' AND csd.workerid = '{2}'
      AND TRUNC(csd.plannedfinishdate) >= TRUNC(SYSDATE) - 7 AND TRUNC(csd.plannedfinishdate) <= TRUNC(SYSDATE) + 7
      AND (csd.recvemployeeid IS NULL OR csd.recvemployeeid = '{2}') {3}";

        if (obj["mfgordername"] != null && obj["mfgordername"].ToString() != "")
        {
            sql += string.Format(" AND cci.mfgordername LIKE '%{0}%'",obj["mfgordername"].ToString()); 
        }

        if (obj["productname"] != null && obj["productname"].ToString() != "")
        {
            sql += string.Format(" AND cci.productname LIKE '%{0}%'", obj["productname"].ToString());
        }
            
            sql += @"
           
UNION ALL

--查询派工给多个人的情况
SELECT cci.mfgordername,f.factoryname,w.workcentername,t.teamname,rd.resourcename,rd.description resourcedesc,
       cci.containername,ws.workflowstepname,cci.workflowstepname currentspec,csd.plannedstartdate,csd.plannedfinishdate,csd.qty,
       e.fullname receiver,csd.recvdate,'{0}' worker,
       CASE WHEN csd.recvemployeeid IS NULL THEN '未领工'
            WHEN csd.recvemployeeid IS NOT NULL THEN '未报工'
       END status,
       CASE WHEN cci.workflowstepid = csd.workflowstepid AND csd.recvemployeeid IS NULL THEN '是' ELSE '否' END receivestate,
       CASE WHEN cci.workflowstepid = csd.workflowstepid AND csd.recvemployeeid IS NOT NULL AND NVL(csd.iscomplete,0) = 0 THEN '是' ELSE '否' END reportstate
FROM containercurrentinfo cci
INNER JOIN containerstepdispatch csd ON csd.containerid = cci.containerid
INNER JOIN containerstepdispatchdetail csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
LEFT JOIN employee e ON e.employeeid =  csd.recvemployeeid
LEFT JOIN team t ON t.teamid = csd.teamid
LEFT JOIN workcenter w ON w.workcenterid = csd.workcenterid
LEFT JOIN workflowstep ws ON ws.workflowstepid = csd.workflowstepid
LEFT JOIN employee e2 ON e2.employeeid = csdd.workerid
LEFT JOIN factory f ON f.factoryid = csd.factoryid
LEFT JOIN resourcedef rd ON rd.resourceid = csd.resourceid
WHERE cci.isinstore = 0 AND cci.containerstatus = 1 AND csd.isuse = 0 AND NVL(csd.iscomplete,0) = 0 AND csd.workerid IS NULL 
      AND csd.factoryid = '{1}' AND csdd.workerid = '{2}'
      AND TRUNC(csd.plannedfinishdate) >= TRUNC(SYSDATE) - 7 AND TRUNC(csd.plannedfinishdate) <= TRUNC(SYSDATE) + 7
      AND (csd.recvemployeeid IS NULL OR csd.recvemployeeid = '{2}') {3}";

            if (obj["mfgordername"] != null && obj["mfgordername"].ToString() != "")
            {
                sql += string.Format(" AND cci.mfgordername LIKE '%{0}%'", obj["mfgordername"].ToString());
            }

            if (obj["productname"] != null && obj["productname"].ToString() != "")
            {
                sql += string.Format(" AND cci.productname LIKE '%{0}%'", obj["productname"].ToString());
            }
        
        string strCondition = "";
        if (obj["containername"] != null && obj["containername"].ToString() != "")
        {
            strCondition = string.Format(" AND cci.containername = '{0}'", obj["containername"].ToString());
        }
        sql = string.Format(sql, obj["workername"].ToString(), obj["factoryid"].ToString(), obj["workerid"].ToString(), strCondition);
        return sql;
    }

    //查询已派工未报工工序数
    uMESProcessResult getUnReportWorkflowStepCount(JObject obj)
    {
        string sql = getUnReportWorkflowStepCountSql(obj);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    //查询已派工未报工工序明细
    uMESProcessResult getUnReportWorkflowStepDetail(JObject obj)
    {
        string sql = getUnReportWorkflowStepCountSql(obj);
        uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
        paraPage.CurrentPageIndex = Convert.ToInt32(obj["currentPage"].ToString());//页码
        paraPage.PageSize = Convert.ToInt32(obj["pageSize"].ToString());//每页页数
        paraPage.strSQL = sql;
        uMESProcessResult result = DatabaseHelper.RunProcedureForPage(paraPage);
        foreach (DataColumn col in result.DBTable.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = result.DBTable, RowCount = result.RowCount.ToString(), Code = "200", Message = "请求成功" };
    }

    uMESProcessResult getNCProgramData(JObject obj)
    {
        string process_no = "";
        string sql = string.Format("SELECT wf.process_no FROM workflow wf WHERE wf.workflowid = '{0}'", obj["workflowid"].ToString());
        DataTable dtWorkflow = DatabaseHelper.Query_ReturnDatTable(sql);
        if (dtWorkflow.Rows.Count > 0)
        {
            process_no = dtWorkflow.Rows[0]["process_no"].ToString();
        }
        sql = string.Format("SELECT * FROM ncprogram t WHERE t.productname like '{0}%' AND t.process_no = '{1}'", obj["productname"].ToString(), process_no);
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }

    uMESProcessResult getNCProgramDetail(JObject obj)
    {
        string sql = string.Format("SELECT * FROM ncprogramdetaile ncd WHERE ncd.parentid = '{0}'", obj["parentid"].ToString());
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        return new uMESProcessResult() { ReturnData = dt, RowCount = dt.Rows.Count.ToString(), Code = "200", Message = "请求成功" };
    }
}